package cn.tedu.springdemo.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

import java.util.Iterator;

/**
 *
 */
@Component
public class BFPPDemo implements BeanFactoryPostProcessor {
    Logger logger = LoggerFactory.getLogger(BFPPDemo.class);
    /**
     * postProcessBeanFactory 方法在Spring 加载全部Bean定义以后执行
     * configurableListableBeanFactory 对象中包含全部的bean定义信息
     * @param configurableListableBeanFactory
     * @throws BeansException
     */
    @Override
    public void postProcessBeanFactory(
            ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        //configurableListableBeanFactory 中也包含，我们字节定义的Bean信息
        //configurableListableBeanFactory 中也包含，我们字节定义的Bean信息 DemoBean和ExampleBean
        //getBeanNamesIterator() 返回Spring中加载的全部的Bean的name
        Iterator<String> names = configurableListableBeanFactory.getBeanNamesIterator();
        for(; names.hasNext();){
            String name = names.next();
            logger.debug("{}", name);
        }
    }
}
